{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 获取哪些信息\n",
    "\n",
    "主机名：通过名称识别资产的作用、位置等信息\n",
    "mac地址：网卡信息，可以作为主机的唯一标识\n",
    "SN：物理服务器、网络设备有的唯一资产标示\n",
    "系统版本：服务器系统的具体版本 Redhat5.5\n",
    "服务器机型：Dell R610、HPDL580\n",
    "\n",
    "\n",
    "##############################################\n",
    "## 获取主机名命令\n",
    "hostname\n",
    "uname -a\n",
    "cat /etc/sysconfig/network\n",
    "\n",
    "##############################################\n",
    "## 获取系统版本\n",
    "cat /etc/issue\n",
    "cat /etc/redhat-release\n",
    "uname\n",
    "lsb_release\n",
    "\n",
    "##############################################\n",
    "## 获取mac地址\n",
    "linux系统：\n",
    "    cat /sys/class/net/eth0/address\n",
    "    或\n",
    "    ## 排除以其他字母开头的非物理网卡信息（docker 网卡未排除）\n",
    "    cat /sys/class/net/[^vtlsb]*/address\n",
    "    ifconfig eth0\n",
    "    ip a\n",
    "ESXI:\n",
    "    esxcfg-vmknic -l\n",
    "    # 按列切割，选择第8列，并选出带有冒号（：）的行，网卡地址的行\n",
    "    esxcfg-vmknic -l ｜ awk '{print $8}' | grep ':'\n",
    "\n",
    "\n",
    "两种系统的组合：\n",
    "cat /sys/class/net/[^vtlsb]*/address || esxcfg-vmknic -l ｜ awk '{print $8}' | grep ':'\n",
    "\n",
    "##############################################\n",
    "## 获取服务器硬件机型\n",
    "安装 \n",
    "    yum install dmidecode\n",
    "    apt-get install dmidecode\n",
    "\n",
    "dmidecode -s system-manufacture\n",
    "dmidecode -s system-product-name\n",
    "\n",
    "##############################################\n",
    "## 获取物理机服务器序列号\n",
    "dmidecode -s system-serial-number\n",
    "\n",
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
